package cn.gxljc.technology.store_management.mapper;

import cn.gxljc.technology.store_management.entity.Warehouse;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
 **@author LuoShengYing
 **@date 2021/6/19
 * WarehouseMapper用于管理warehouse(仓库)表
 */
@Mapper
public interface WarehouseMapper {

    // 查询全部仓库数据
    @Select("select * from `warehouse`")
    List<Warehouse> selectAllWarehouse();

    // 通过warehouseID查询对应的Warehouse数据
    @Select("select * from `warehouse` where `warehouseID` = #{warehouseID}")
    Warehouse selectWarehouseByID(int warehouseID);

    // 通过warehouseName查询对应的warehouse数据
    @Select("select * from `warehouse` where `warehouseName` = #{warehouseName}")
    Warehouse selectWarehouseByName(String warehouseName);

    // 新增warehouse数据，并将自增的warehouseID注入到传入的warehouse对象
    @Insert("insert `warehouse` set `warehouseName` = #{warehouseName}, `warehouseAddress` = #{warehouseAddress}")
    @Options(useGeneratedKeys = true, keyProperty = "warehouseID")
    void insertWarehouse(Warehouse warehouse);

    // 通过warehouseID，更新warehouse数据，并返回boolean类型数据判断成功与否
    @Update("update `warehouse` set `warehouseName` = #{warehouseName}, `warehouseAddress` = #{warehouseAddress} where `warehouseID` = #{warehouseID}")
    boolean updateWarehouseByID(Warehouse warehouse);

    // 通过warehouseID删除，warehouse数据，并返回boolean类型数据判断成功与否
    @Delete("delete from `warehouse` where `warehouseID` = #{warehouseID}")
    boolean deleteWarehouseByID(int warehouseID);
}
